package cn.xhb.controller;

import cn.xhb.domain.User;
import cn.xhb.service.UserService;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @RequestMapping("/login")
    public String login(User user, HttpServletRequest request){
         user=userService.login(user.getUserName(),user.getPassword());
            if (user!=null){
                request.getSession().setAttribute("user",user);
                return "redirect:/content/list";
            }else {
                return "fail";
            }
    }
    @RequestMapping("/add")
    public String add(User user){
        userService.add(user);
        return "login";
    }
    @RequestMapping("/remove")
    public String removeSession(HttpSession session){
        session.removeAttribute("user");
        return "login";
    }

}
